<?php


class FirstPage
{	
	/**
	*@var LoginValidation
	**/
	private $loginValidation;
	/**
	*@var string
	**/
	private static $username = "FirstPage::userName";
	/**
	*@var string
	**/
	private static $password = "FirstPage::password";

	/**
	*@param LoginValidation
	**/
	public function __construct(LoginValidation $loginVal)
	{
		$this->loginValidation = $loginVal;
	}

	/**
	*@return string
	**/
	public function getFirstPage()
	{
		$body = $this->getFirstPageHeader();
		$body .= $this->getLoginForm();
		$body .= $this->getFirstPageFooter();

		return $body;
	}

	/**
	*@return string
	**/
	private function getFirstPageHeader()
	{
		$header = "<h1>Träningsdagboken!</h1>";
		return $header;

	}

	/**
	*@return string
	**/
	private function getLoginForm()
	{
		$username = $this->getUsername();
		$message;
		if($this->justCreatedNewMember())
		{
			$message = "Registreringen lyckades!";
		}
		else
		{
			$message = $this->loginValidation->getErrorMessage();
		}
		

		return "
		<div id='loginformDiv' >
			<a href='RegisterMember.php'>Registrera ny användare</a>
			<form action='?login' method='post' enctype='multipart/form-data'>
				<fieldset>
					$message
					<legend>Logga in - Användarnamn och Lösenord</legend>
					<label for='UserNameID' >Användarnamn :</label>
					<input type='text' size='20' name='" . self::$username . "' id='UserNameID' value='$username' />
					<label for='PasswordID' >Lösenord  :</label>
					<input type='password' size='20' name='" . self::$password . "' id='PasswordID' value='' />
					<input type='submit' name=''  value='Logga in' />
				</fieldset>
			</form>
		</div>";
	}


	/**
	*@return string
	**/
	public function getFirstPageFooter()
	{
		$footer = "<a>Robert Forsgren</a> <a>Träningsdagboken</a>" ;
		return $footer;
	}

	/**
	*@return boolean
	**/
	private function justCreatedNewMember()
	{
		if(isset($_GET['newMember']))
		{
			return true;
		}
		return false;
	}

	/**
	*@return string session
	**/
	public function getUsername()
	{
		if(isset( $_POST[self::$username]))
		{
			return $_POST[self::$username];
		}
		return "";
	}

	/**
	*@return string session
	**/
	public function getPassword()
	{
		if(isset($_POST[self::$password]))
		{
			return $_POST[self::$password];
		}
		return "";
	}


}